import { ConfigManager } from "../../../com/gengine/resource/ConfigManager";
import { TLoadReward } from "../../../Message/Db/Tables/TLoadReward";
import { StringHelper } from "../../../com/gengine/utils/StringHelper";
type int = number;
//class LoadRewardConfig
    
    export  class LoadRewardConfig
    {
        constructor()
        {
            
            this._map = new Map<any, any> /* flash.utils.Dictionary */();
            this._rewardArr = [];
            this._rewardDayArr = [];
            this._sevenMap = new Map<any, any> /* flash.utils.Dictionary */();
            if (LoadRewardConfig._instance != null) 
            {
                throw new Error("LoadRewardConfig单例");
            }
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            var loc1=ConfigManager.instance.getJSONByFileName("t_load_reward.json");
            this.write(loc1);
            return;
        }

        /* internal  */write(arg1: Object): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=arg1;
            for(loc2 of loc4) 
            {
                loc1 = new TLoadReward();
                loc1.type = loc2.type;
                loc1.day = loc2.day;
                loc1.rewardNotRecharge = StringHelper.getString(loc2.rewardNotRecharge);
                loc1.rewardRecharge = StringHelper.getString(loc2.rewardRecharge);
                if (loc1.type == 0) 
                {
                    this._map[loc1.day] = loc1;
                    this._rewardArr.push(loc1);
                    this._rewardDayArr.push(loc1.day);
                    continue;
                }
                if (loc1.type != 1) 
                {
                    continue;
                }
                this._sevenMap[loc1.day] = loc1.rewardNotRecharge;
            }
            this._rewardDayArr.sort(Array.NUMERIC);
            return;
        }

        public getSevenDaysReward(arg1: int, arg2: int): Array<any>
        {
            var loc5=null;
            var loc6=0;
            var loc1=[];
            var loc2=this._sevenMap[arg1];
            var loc3=[];
            var loc4=[];
            if (loc2 != "") 
            {
                loc3 = loc2.split("#");
                loc6 = 0;
                while (loc6 < loc3.length) 
                {
                    loc4 = (loc5 = loc3[loc6] as string).split(",");
                    if ((parseInt(loc4[0]) & arg2) != 0) 
                    {
                        loc1.push(loc4);
                    }
                    ++loc6;
                }
            }
            return loc1;
        }

        public getLoadRewardByDay(arg1: int): TLoadReward
        {
            return this._map[arg1];
        }

        public getLoadRewardArray(): Array<any>
        {
            return this._rewardArr;
        }

        public getNextRewardByDay(arg1: int): int
        {
            var loc1=0;
            var loc2=0;
            var loc3=0;
            if (arg1 <= 0) 
            {
                loc1 = 1;
            }
            else 
            {
                arg1 = arg1 % 60 + 1;
                loc3 = arg1;
                while (loc3 <= 60) 
                {
                    loc2 = this._rewardDayArr.indexOf(loc3);
                    if (loc2 != -1) 
                    {
                        break;
                    }
                    ++loc3;
                }
                loc1 = this._rewardDayArr[loc2];
            }
            return loc1;
        }

        public static get instance(): LoadRewardConfig
        {
            if (LoadRewardConfig._instance == null) 
            {
                LoadRewardConfig._instance = new LoadRewardConfig();
            }
            return LoadRewardConfig._instance;
        }

        /* internal */ /* var */_map: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_rewardArr: Array<any>;

        /* internal */ /* var */_rewardDayArr: Array<any>;

        /* internal */ /* var */_sevenMap: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ static /* var */_instance: LoadRewardConfig;
    }
